home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 2 / Macwelt DVD 2.cdr / System / Internet-Utilities / macosx / News Mac 1.1.dmg / Config.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-04-08  |  6.6 KB  |  234 lines

  1. import java.awt.Color;
  2. import java.io.FileInputStream;
  3. import java.io.Serializable;
  4. import java.util.Properties;
  5.  
  6. public class Config implements Serializable {
  7.    protected static final String NAME = "NewsMac";
  8.    protected static final String VERSION = "1.1";
  9.    protected static final int MAJOR_VERSION = 1;
  10.    protected static final int MINOR_VERSION = 1;
  11.    protected static final Color SELECTION_COLOUR = new Color(49, 140, 222);
  12.    protected static final String CHANNEL_PATH = "newsmac.app/contents/resources/";
  13.    protected static final String CHANNEL_DATABASE = "channel_database.data";
  14.    protected static final String USER_CHANNEL_PATH = "/library/channels/";
  15.    protected static final String CONFIG_PATH = "/library/preferences/";
  16.    protected static final String IMAGE_PATH = "newsmac.app/contents/resources/";
  17.    protected static final String CHANNEL_SETTINGS = "/library/preferences/NewsMac Channel Settings";
  18.    protected static final String SYSTEM_FONT = "Lucida Grande";
  19.    protected static final String ONLINE_DATABASE = "http://homepage.mac.com/roryp/channel_database.data";
  20.    protected static final String UPDATE = "http://homepage.mac.com/roryp/update.data";
  21.    protected static final String HOMEPAGE = "http://users.aber.ac.uk/rlp9/newsmac";
  22.    private String home = "";
  23.    private boolean cache = false;
  24.    private boolean broadband = true;
  25.    private boolean checkForUpdate = true;
  26.    private boolean checkForChannelUpdate = true;
  27.    private boolean myNewsSwitch = true;
  28.    private boolean autoDownload = true;
  29.    private boolean downloadAll = false;
  30.    private boolean downloadFavorites = true;
  31.    private boolean saveChannelState = true;
  32.    private boolean saveAllHeadlines = false;
  33.  
  34.    protected String getHome() {
  35.       return this.home;
  36.    }
  37.  
  38.    protected void setHome(String theValue) {
  39.       this.home = theValue;
  40.    }
  41.  
  42.    protected void setCheckUpdate(boolean value) {
  43.       this.checkForUpdate = value;
  44.    }
  45.  
  46.    protected boolean isCheckUpdate() {
  47.       return this.checkForUpdate;
  48.    }
  49.  
  50.    protected void setCheckChannelUpdate(boolean value) {
  51.       this.checkForChannelUpdate = value;
  52.    }
  53.  
  54.    protected boolean isCheckChannelUpdate() {
  55.       return this.checkForChannelUpdate;
  56.    }
  57.  
  58.    protected void setAutoDownload(boolean value) {
  59.       this.autoDownload = value;
  60.    }
  61.  
  62.    protected boolean isAutoDownload() {
  63.       return this.autoDownload;
  64.    }
  65.  
  66.    protected void setDownloadAdd(boolean value) {
  67.       this.downloadAll = value;
  68.    }
  69.  
  70.    protected boolean isDownloadAdd() {
  71.       return this.downloadAll;
  72.    }
  73.  
  74.    protected void setDownloadFavorites(boolean value) {
  75.       this.downloadFavorites = value;
  76.    }
  77.  
  78.    protected boolean isDownloadFavorites() {
  79.       return this.downloadFavorites;
  80.    }
  81.  
  82.    protected void setBroadband(boolean speed) {
  83.       this.broadband = speed;
  84.    }
  85.  
  86.    protected boolean isBroadband() {
  87.       return this.broadband;
  88.    }
  89.  
  90.    protected void setMyNewsSwitch(boolean value) {
  91.       this.myNewsSwitch = value;
  92.    }
  93.  
  94.    protected boolean isMyNewsSwitch() {
  95.       return this.myNewsSwitch;
  96.    }
  97.  
  98.    protected void setSaveState(boolean value) {
  99.       this.saveChannelState = value;
  100.    }
  101.  
  102.    protected boolean isSaveState() {
  103.       return this.saveChannelState;
  104.    }
  105.  
  106.    protected void setSaveAll(boolean value) {
  107.       this.saveAllHeadlines = value;
  108.    }
  109.  
  110.    protected boolean isSaveAll() {
  111.       return this.saveAllHeadlines;
  112.    }
  113.  
  114.    protected boolean isCache() {
  115.       return this.cache;
  116.    }
  117.  
  118.    protected void setCache(boolean value) {
  119.       this.cache = value;
  120.    }
  121.  
  122.    protected void savePrefs() throws Exception {
  123.       String configString = "# NewsMac 1.1 Preferences File\n# This is a generated file - DO NOT EDIT!\n\nBroadband=" + this.broadband + "\n" + "Download_favorites=" + this.downloadFavorites + "\n" + "Download_all=" + this.downloadAll + "\n" + "Cache=" + this.cache + "\n" + "Check_for_updates=" + this.checkForUpdate + "\n" + "Check_for_channels=" + this.checkForChannelUpdate + "\n" + "Auto_download=" + this.autoDownload + "\n" + "My_news_switch=" + this.myNewsSwitch + "\n" + "Save_state=" + this.saveChannelState + "\n" + "Save_all=" + this.saveAllHeadlines;
  124.  
  125.       try {
  126.          IOUtil.saveTextFile(this.getPrefsFile(), configString, false);
  127.       } catch (Exception var3) {
  128.          throw new Exception("Config: Error saving preferences.\n\t" + var3);
  129.       }
  130.    }
  131.  
  132.    protected void loadPrefs() throws Exception {
  133.       try {
  134.          Properties props = new Properties();
  135.          props.load(new FileInputStream(this.getPrefsFile()));
  136.          if (props.getProperty("Broadband").equals("true")) {
  137.             this.broadband = true;
  138.          } else {
  139.             this.broadband = false;
  140.          }
  141.  
  142.          if (props.getProperty("Download_favorites").equals("true")) {
  143.             this.downloadFavorites = true;
  144.          } else {
  145.             this.downloadFavorites = false;
  146.          }
  147.  
  148.          if (props.getProperty("Download_all").equals("true")) {
  149.             this.downloadAll = true;
  150.          } else {
  151.             this.downloadAll = false;
  152.          }
  153.  
  154.          if (props.getProperty("Cache").equals("true")) {
  155.             this.cache = true;
  156.          } else {
  157.             this.cache = false;
  158.          }
  159.  
  160.          if (props.getProperty("Check_for_updates").equals("true")) {
  161.             this.checkForUpdate = true;
  162.          } else {
  163.             this.checkForUpdate = false;
  164.          }
  165.  
  166.          if (props.getProperty("Check_for_channels").equals("true")) {
  167.             this.checkForChannelUpdate = true;
  168.          } else {
  169.             this.checkForChannelUpdate = false;
  170.          }
  171.  
  172.          if (props.getProperty("Auto_download").equals("true")) {
  173.             this.autoDownload = true;
  174.          } else {
  175.             this.autoDownload = false;
  176.          }
  177.  
  178.          if (props.getProperty("My_news_switch").equals("true")) {
  179.             this.myNewsSwitch = true;
  180.          } else {
  181.             this.myNewsSwitch = false;
  182.          }
  183.  
  184.          if (props.getProperty("Save_state").equals("true")) {
  185.             this.saveChannelState = true;
  186.          } else {
  187.             this.saveChannelState = false;
  188.          }
  189.  
  190.          if (props.getProperty("Save_all").equals("true")) {
  191.             this.saveAllHeadlines = true;
  192.          } else {
  193.             this.saveAllHeadlines = false;
  194.          }
  195.  
  196.       } catch (Exception var2) {
  197.          throw new Exception("Config: Could not load preferences\n\t" + var2);
  198.       }
  199.    }
  200.  
  201.    protected String getKeywordFile() {
  202.       return this.home + "/library/preferences/" + "NewsMac Keywords";
  203.    }
  204.  
  205.    protected String getPrefsFile() {
  206.       return this.home + "/library/preferences/" + "NewsMac Preferences";
  207.    }
  208.  
  209.    protected String getCacheDir(boolean url) {
  210.       return this.home + "/library/preferences/" + "NewsMac%20Cache/";
  211.    }
  212.  
  213.    protected String getCacheDir() {
  214.       return this.home + "/library/preferences/" + "NewsMac Cache/";
  215.    }
  216.  
  217.    protected void checkConfigDir() throws Exception {
  218.       if (!IOUtil.fileExists(this.home + "/library/preferences/")) {
  219.          throw new Exception("Unable to locate user preferences directory!");
  220.       }
  221.    }
  222.  
  223.    protected void checkCacheDir() {
  224.       if (!IOUtil.fileExists(this.home + "/library/preferences/" + "NewsMac Cache/")) {
  225.          try {
  226.             IOUtil.makeDirectory(this.home + "/library/preferences/" + "NewsMac Cache/");
  227.          } catch (Exception var2) {
  228.             System.out.println(((Throwable)var2).toString());
  229.          }
  230.       }
  231.  
  232.    }
  233. }
  234.